package com.wxp.demo05.button;

import android.os.Bundle;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.wxp.demo05.R;

/**
 * 2.3 单选按钮RadioButton
 */
public class RadioButtonActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener {

    private TextView tv_state1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_radio_button);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        this.setTitle("2.3 单选按钮RadioButton");

        RadioGroup rb_sex1 = this.findViewById(R.id.rb_sex1);
        tv_state1 = this.findViewById(R.id.tv_state1);

        rb_sex1.setOnCheckedChangeListener(this);

    }

    @Override
    public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
        String selectStateText = radioGroup.getContext().getString(R.string.select_state);
        if (checkedId == R.id.rb_sex1_man) {
            tv_state1.setText(selectStateText + radioGroup.getContext().getString(R.string.sex_man));
        } else if (checkedId == R.id.rb_sex1_girl) {
            tv_state1.setText(selectStateText + radioGroup.getContext().getString(R.string.sex_girl));
        }
    }
}